export * from './SceneViewer';
import SceneViewer from './SceneViewer.vue';
import type { App } from 'vue';
import {  defaultConfig, SceneViewerConfigKey } from './SceneViewer';
import type { SceneViewerConfig  } from './SceneViewer';
import { loadSystemjsImportmap, loadScript, combinPath, merge } from './ScriptLoader';

const vuePlugin = {
  install: async (Vue: App, config: SceneViewerConfig) => {
    Vue.component('SceneViewer', SceneViewer);
    const mergedConfig = merge(defaultConfig, config);
    Vue.provide(SceneViewerConfigKey, mergedConfig);
    await loadSystemjsImportmap(mergedConfig);
    await loadScript(combinPath(mergedConfig.serverPath, mergedConfig.polyfillsPath));
    await loadScript(combinPath(mergedConfig.serverPath, mergedConfig.systemjsPath));
  },
};
export default vuePlugin;

export function useSceneViewer(Vue: App, config: SceneViewerConfig) {
  vuePlugin.install(Vue, config);
}
